//
//  WZTaskManagerCell.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/6/8.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "WZTaskManagerCell.h"
#import "WZTask.h"
#import "WZFinished.h"

@interface WZTaskManagerCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *startTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *endTimeLabel;
@property (weak, nonatomic) IBOutlet UIImageView *progressImgView;

@end

@implementation WZTaskManagerCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}
- (void)setTaskList:(WZTask *)taskList {
    
    _taskList = taskList;
    
    
    // 知会我的
    if (![self.oaUserId isEqualToString:taskList.executorId] && ![self.oaUserId isEqualToString:taskList.assignerId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_Notify"];
        
        // 我是分配人不是执行者
    } else if ([self.oaUserId isEqualToString:taskList.assignerId] && ![self.oaUserId isEqualToString:taskList.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_assigner"];
        
        // 我是执行者不是分配者
    } else if (![self.oaUserId isEqualToString:taskList.assignerId] && [self.oaUserId isEqualToString:taskList.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_executor"];
        
        // 执行和分配是同一个人
    } else if ([self.oaUserId isEqualToString:taskList.assignerId] && [self.oaUserId isEqualToString:taskList.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_executor"];
    }
    
    self.startTimeLabel.text = [NSString stringWithFormat:@"开始于%@", taskList.planExecBeginDate];
    self.endTimeLabel.text = [NSString stringWithFormat:@"截止于%@", taskList.planExecEndDate];
    self.titleLabel.text = taskList.taskName;
    
//    if ([taskList.taskType isEqualToString:@"taskTypes_1"]) {
//        
//        self.iconImageView.image = [UIImage imageNamed:@"shape-15"];
//        
//    } else if ([taskList.taskType isEqualToString:@"taskTypes_2"]) {
//        
//        self.iconImageView.image = [UIImage imageNamed:@"shape-16"];
//        
//    } else {
//        
//        self.iconImageView.image = [UIImage imageNamed:@"@"];
//    }
    
    if ([taskList.progress intValue] < 25) {
        self.progressImgView.image = [UIImage imageNamed:@"z-1"];
    } else if ([taskList.progress intValue] < 50) {
        self.progressImgView.image = [UIImage imageNamed:@"z-2"];
    } else if ([taskList.progress intValue] < 75) {
        self.progressImgView.image = [UIImage imageNamed:@"z-3"];
    } else if ([taskList.progress intValue] < 50) {
        self.progressImgView.image = [UIImage imageNamed:@"z-2"];
    }
    
}


- (void)setFinshed:(WZFinished *)finshed {
    
    _finshed = finshed;
    
    // 知会我的
    if (![self.oaUserId isEqualToString:finshed.executorId] && ![self.oaUserId isEqualToString:finshed.assignerId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_Notify"];
        
        // 我是分配人不是执行者
    } else if ([self.oaUserId isEqualToString:finshed.assignerId] && ![self.oaUserId isEqualToString:finshed.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_assigner"];
        
        // 我是执行者不是分配者
    } else if (![self.oaUserId isEqualToString:finshed.assignerId] && [self.oaUserId isEqualToString:finshed.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_executor"];
        
        // 执行和分配是同一个人
    } else if ([self.oaUserId isEqualToString:finshed.assignerId] && [self.oaUserId isEqualToString:finshed.executorId]) {
        
        self.iconImageView.image = [UIImage imageNamed:@"TaskManager_assigner"];
    }
    
    self.startTimeLabel.text = [NSString stringWithFormat:@"开始于%@", finshed.planExecBeginDate];
    self.endTimeLabel.text = [NSString stringWithFormat:@"截止于%@", finshed.planExecEndDate];
    self.titleLabel.text = finshed.taskName;
    
    if ([finshed.statusName isEqualToString:@"已完成"]) {
        
        self.progressImgView.image = [UIImage imageNamed:@"z-5"];
        
    } else if ([finshed.statusName isEqualToString:@"已终止"]) {
        
        self.progressImgView.image = [UIImage imageNamed:@"z-6"];
        
    } else {
        
        WZLog(@"其他情况");
    }
}

///**get TimeStamp Unit: sss , length = 13 */
////从1970年开始到现在经过了多少秒
//-(NSString *)getTimeSp
//{
//    NSString *time;
//    NSDate *fromdate=[NSDate date];
//    time = [NSString stringWithFormat:@"%f",[fromdate timeIntervalSince1970]*1000];
//    return time;
//}
//
///**TimeStamp2NSDate */
////将时间戳转换成NSDate,转换的时间为格林尼治时间
//-(NSDate *)changeSpToTime:(NSString*)spString
//{
//    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString doubleValue]/1000];
//    NSLog(@"%@",confromTimesp);
//    
//    return confromTimesp;
//    
//}
//
///**TimeStamp2NSDate  result = 北京时间 */
////将时间戳转换成NSDate,加上时区偏移。这个转换之后是北京时间
//-(NSDate*)zoneChange:(NSString*)spString
//{
//    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[spString doubleValue]/1000];
//    NSTimeZone *zone = [NSTimeZone systemTimeZone];
//    NSInteger interval = [zone secondsFromGMTForDate:confromTimesp];
//    NSDate *localeDate = [confromTimesp  dateByAddingTimeInterval: interval];
//    NSLog(@"%@",localeDate);
//    return localeDate;
//}
//
///**时间差*/
////比较给定NSDate与当前时间的时间差，返回相差的秒数
//-(long)timeDifference:(NSDate *)date
//{
//    NSDate *localeDate = [NSDate date];
//    long difference = fabs([localeDate timeIntervalSinceDate:date]);
//    return difference;
//}
//
///**NSDate2NSString */
////将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
//-(NSString*)nsdateToString:(NSDate *)date
//{
//    NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
//    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    // [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
//    NSString* string=[dateFormat stringFromDate:date];
//    NSLog(@"%@",string);
//    return string;
//}
//
///**NSString2TimeStamp */
////将yyyy-MM-dd HH:mm:ss格式时间转换成时间戳
//-(long)changeTimeToTimeSp:(NSString *)timeStr
//{
//    long time;
//    NSDateFormatter *format=[[NSDateFormatter alloc] init];
//    [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    NSDate *fromdate=[format dateFromString:timeStr];
//    time= (long)[fromdate timeIntervalSince1970];
//    NSLog(@"%ld",time);
//    return time;
//}
//
///**get system NSDate */
////获取当前系统的yyyy-MM-dd HH:mm:ss格式时间
//-(NSString *)getTime
//{
//    NSDate *fromdate=[NSDate date];
//    NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
//    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//    NSString* string=[dateFormat stringFromDate:fromdate];
//    return string;
//}
//
///**NowDat2DateFormatter*/
////将当前时间转化为年月日格式
//-(NSString *)changeDate
//{
//    NSDate *date = [NSDate date];
//    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
//    NSInteger unitFlags =  NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
//    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
//    
//    NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
//    NSInteger year = [comps year];
//    NSInteger month = [comps month];
//    NSInteger day = [comps day];
//    NSInteger hour = [comps hour];
//    NSInteger min = [comps minute];
//    NSInteger sec = [comps second];
//    
//    NSString *string = [NSString stringWithFormat:@"%zd年%zd月%zd日%zd时%zd分%zd秒",year,month,day,hour,min,sec];
//    
//    NSLog(@"%@",string);
//    return string;
//}
//
//
///**从NSDate 中提取年月日和时间*/
//- (NSString *) getDateStrAndTimeStr:(NSDate *)date {
//    
//    NSDate *date1 = date;
//    NSDateFormatter *dateFormatter   = [[NSDateFormatter alloc] init];
//    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC+05:30"]];
//    
//    [dateFormatter setDateFormat:@"MM/dd/yyyy HH:mm:ss a"];
//    
//    NSString * dateString =[dateFormatter stringFromDate:date1];
//    NSLog(@"dateString   = %@",dateString);
//    NSLog(@"dateString1   = %@",dateString);
//    
//    //NSDate convert to NSString
//    [dateFormatter setDateFormat:@"HH:mm:ss a"];
//    
//    NSString *strDate = [dateFormatter stringFromDate:date];
//    NSLog(@"strDate   = %@",strDate);
//    return strDate;
//}

//
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//
//    // Configure the view for the selected state
//}


//
//+ (instancetype)taskManagerCellWithTableView:(UITableView *)tableView {
//    static NSString *cell_ID = @"taskManagerCell_ID";
//    WZTaskManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_ID];
//    if (!cell) {
//        cell = [[WZTaskManagerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_ID];
//    }
//    return cell;
//}
//
//
//- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
//    
//    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
//        
//        UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shape-16"]];
//        [self.contentView addSubview:imgView];
//        self.ImgView = imgView;
//        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.contentView.mas_left).offset(20);
//            make.centerY.equalTo(self.contentView.mas_centerY);
//        }];
//        
//        UILabel *taskLabel = [[UILabel alloc] init];
//        taskLabel.textAlignment = NSTextAlignmentCenter;
//        taskLabel.font = Font12;
//        taskLabel.text = @"任务标题";
//        [taskLabel sizeToFit];
//        [self.contentView addSubview:taskLabel];
//        
//        [taskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            
//            make.left.equalTo(imgView.mas_right).offset(20);
//            make.top.equalTo(imgView.mas_top).offset(-3);
//        }];
//        
//        UILabel *endTimeLabel = [[UILabel alloc] init];
//        endTimeLabel.textAlignment = NSTextAlignmentCenter;
//        endTimeLabel.text = [NSString stringWithFormat:@"截止于%d-%d %2d:%2d", 3, 5, 13, 0];
//        endTimeLabel.textColor = GrayColor;
//        endTimeLabel.font = Font10;
//        [self.contentView addSubview:endTimeLabel];
//        [endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.leading.equalTo(taskLabel.mas_leading);
//            make.bottom.equalTo(imgView.mas_bottom).offset(3);
//        }];
//        
//        
//        UILabel *beginTimeLabel = [[UILabel alloc] init];
//        beginTimeLabel.backgroundColor = ClearColor;
//        beginTimeLabel.font = Font10;
//        beginTimeLabel.textColor = GrayColor;
//        beginTimeLabel.text = [NSString stringWithFormat:@"[开始于:%d-%d %2d:%2d]", 3, 4, 13,0];
//        [beginTimeLabel sizeToFit];
//        [self.contentView addSubview:beginTimeLabel];
//        [beginTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(taskLabel.mas_top);
//            make.right.equalTo(self.contentView.mas_right).offset(-20);
//        }];
//    }
//    return self;
//}


@end
